package hu.uszeged.inf.stud.prf.todo.dao.task;

import java.util.List;

import hu.uszeged.inf.stud.prf.todo.dao.core.GenericHibernateDAO;
import hu.uszeged.inf.stud.prf.todo.entity.task.TaskType;
import hu.uszeged.inf.stud.prf.todo.entity.user.User;

public class TaskTypeDAO extends GenericHibernateDAO<TaskType, Long> {

	public TaskTypeDAO() {
		super(TaskType.class);
	}


	@SuppressWarnings("unchecked")
	public List<TaskType> getTaskTypesForUser(User user) {
		StringBuilder query = new StringBuilder();
		query.append("from TaskType tt ");
		query.append("where tt.user = :user and tt.archive=:archive");
		return getSession().createQuery(query.toString())
				.setParameter("user", user)
				.setParameter("archive", false)
				.list();
	}

	public TaskType getTaskTypeByName(String taskTypeName, User user) {
		StringBuilder query = new StringBuilder();
		query.append("from TaskType tt ");
		query.append("where tt.name = :name and tt.user = :user and tt.archive=:archive");
		return (TaskType) getSession().createQuery(query.toString())
				.setParameter("name", taskTypeName)
				.setParameter("user", user)
				.setParameter("archive", false)
				.uniqueResult();
	}

}
